The Magnetic Field is created somehow in the core by unknown origins (speculation suggests that it’s created from the spinning liquid outer core)
It blocks most of the
solar wind and some solar wind goes through
the poles and creates
aurora borealis.